package org.openstreetmap.gui.jmapviewer;

import edu.cicese.alz.swing.SwingUtil;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 4/07/12
 * Time: 03:32 PM
 */
public class MapMarker {
	private Color colorBackground;
	private Color colorBorder;

	private double lat;
	private double lon;
	private double altitude;

	private long timestamp;

	private double distanceFromPrevious;

	private boolean isInLocation = false;
	private int mapLocationID;

	private String label;
	private boolean hasLabel = false;
//	private String day;
//	private String hour;
//	private String distance;
//	private String time;
//	private String speed;

	public MapMarker(double lat, double lon, long timestamp, double distanceFromPrevious, Color colorBackground, Color colorBorder) {
        this.lat = lat;
		this.lon = lon;
		this.timestamp = timestamp;
		this.distanceFromPrevious = distanceFromPrevious;
		this.colorBackground = colorBackground;
		this.colorBorder = colorBorder;
	}

	public MapMarker(double lat, double lon, long timestamp, double distanceFromPrevious, Color colorBackground, Color colorBorder, String label) {
		this(lat, lon, timestamp, distanceFromPrevious, colorBackground, colorBorder);
		this.label = label;
		hasLabel = true;
	}

	public double getLat() {
		return lat;
	}

	public double getLon() {
		return lon;
	}

	public long getTimestamp() {
		return timestamp;
	}

	public double getDistanceFromPrevious() {
		return distanceFromPrevious;
	}

	public void setIsInLocation(boolean inLocation) {
		isInLocation = inLocation;
	}

	public boolean isInLocation() {
		return isInLocation;
	}

	public int getMapLocationID() {
		return mapLocationID;
	}

	public void setMapLocationID(int mapLocationID) {
		this.mapLocationID = mapLocationID;
	}

	public void paint(Graphics g, Point position, boolean showingMarkers, boolean showingLabels) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setStroke(new BasicStroke());

		if (showingMarkers) {
			int radius = 5;
			int diameter = radius * 2;

//			Area areaOne = new Area(new Ellipse2D.Double(position.x - radius, position.y - radius - 8, diameter, diameter));
//			Polygon triangle = new Polygon();
//			triangle.addPoint(position.x - 5, position.y - 7);
//			triangle.addPoint(position.x + 5, position.y - 7);
//			triangle.addPoint(position.x, position.y);
//			Area areaTwo = new Area(triangle);
//			areaOne.add(areaTwo);
//			g2.setColor(colorBackground);
//			g2.fill(areaOne);
//			g2.setColor(colorBorder);
//			g2.draw(areaOne);


			Area area = new Area(new Ellipse2D.Double(position.x - radius, position.y - radius, diameter, diameter));
			g2.setColor(colorBackground);
			g2.setStroke(new BasicStroke());
			g2.fill(area);
		}

		if (showingLabels && hasLabel) {
			int x = position.x + 7, y = position.y - 2;
			g2.setColor(Color.WHITE);
			g2.setFont(SwingUtil.fMap);
			g2.drawString(label, ShiftWest(x, 1), ShiftNorth(y, 1));
			g2.drawString(label, ShiftWest(x, 1), ShiftSouth(y, 1));
			g2.drawString(label, ShiftEast(x, 1), ShiftNorth(y, 1));
			g2.drawString(label, ShiftEast(x, 1), ShiftSouth(y, 1));
			g2.setColor(Color.BLACK);
			g2.drawString(label, x, y);
		}
    }

	int ShiftNorth(int p, int distance) {
		return (p - distance);
	}

	int ShiftSouth(int p, int distance) {
		return (p + distance);
	}

	int ShiftEast(int p, int distance) {
		return (p + distance);
	}

	int ShiftWest(int p, int distance) {
		return (p - distance);
	}
}
